package main

import (
	"fmt"
	"reflect"
)

type student struct {
	Name   string
	Number int
	Height uint
	Weight float64
}

func (s student) Info() {
	fmt.Printf("Name:\t%s\n", s.Name)
	fmt.Printf("Number:\t%03d\n", s.Number)
	fmt.Printf("Height:\t%d cm\n", s.Height)
	fmt.Printf("Weight:\t%.2f kg\n", s.Weight)
}

func (s *student) SetHeightWeight(h uint, w float64) {
	s.Height = h
	s.Weight = w
}

func main() {
	s1 := student{"Jimmy", 1, 170, 65.5}
	st1 := reflect.TypeOf(s1)
	n1, ok := st1.FieldByName("Height")
	fmt.Printf("%#v, %v\n", n1, ok)
	n2, ok := st1.FieldByName("School")
	fmt.Println(n2, ok)
	sv1 := reflect.ValueOf(s1)
	v1 := sv1.FieldByName("Height")
	fmt.Println(v1)
	v2 := sv1.FieldByName("School")
	fmt.Println(v2)
	fmt.Println(v2.String())
	fmt.Println(v2.Kind() == reflect.Invalid)
}
/* 输出结果：
reflect.StructField{Name:"Height", PkgPath:"", Type:(*reflect.rtype)(0x596320), Tag:"", Offset:0x18, Index:[]int{2}, Anonymous:false}, true
{  <nil>  0 [] false} false
170
<invalid reflect.Value>
<invalid Value>
true
*/